﻿<Window x:Class="SellAvi.Views.WindowCustomParams"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
        xmlns:command="http://www.galasoft.ch/mvvmlight"
        DataContext="{Binding CustomParams, Source={StaticResource Locator}}"
        Title="Журнал автообучения SellAvi"
        Width="350"
        Height="500">
    <DockPanel>
        <ToolBarTray DockPanel.Dock="Bottom" Background="White">
            <ToolBar Band="0" BandIndex="0">
                <Button ToolTip="Очистить всю историю обучения" Command="{Binding TruncateAllParamsCommand}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/SellAvi;component/Resources/bstop.png" />
                    </StackPanel>
                </Button>
                <Button ToolTip="Удалить выделенный параметр" Command="{Binding DeleteParamCommand}" IsEnabled="{Binding Path=HasSelectedTreeItem, Mode=OneWay}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/SellAvi;component/Resources/trash.png">
                            <Image.Style>
                                <Style TargetType="Image">
                                    <Style.Triggers>
                                        <Trigger Property="IsEnabled" Value="False">
                                            <Setter Property="Opacity" Value="0.5" />
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </Image.Style>
                        </Image>
                        <TextBlock Margin="5,0,5,0">Удалить</TextBlock>
                    </StackPanel>
                </Button>
                <Button ToolTip="Обновление параметров из базы" Command="{Binding ReBuildParamsTreeCommand}">
                    <StackPanel Orientation="Horizontal">
                        <Image Source="/SellAvi;component/Resources/loop.png" />
                        <TextBlock Margin="5,0,5,0">Обновить</TextBlock>
                    </StackPanel>
                </Button>
            </ToolBar>
        </ToolBarTray>
        <DataGrid
            ItemsSource="{Binding ParamsTree}"
            CanUserAddRows="False"
            IsReadOnly="True"
            HeadersVisibility="None"
            SelectionMode="Single"
            SelectionUnit="FullRow"
            BorderThickness="0"
            VerticalGridLinesBrush="White"
            HorizontalGridLinesBrush="White">
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <command:EventToCommand
                Command="{Binding ParamsSelectionChangedCommand}"
                CommandParameter="{Binding Path=SelectedItem, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=DataGrid}}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>

            <!--Убираем границу вокруг ячейки на которую установлен курсор-->
            <DataGrid.Resources>
                <Style TargetType="DataGridCell">
                    <Setter Property="BorderThickness" Value="0"/>
                    <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
                </Style>
            </DataGrid.Resources>

            <DataGrid.GroupStyle>
                <GroupStyle>
                    <GroupStyle.ContainerStyle>
                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                        <Expander>
                                            <Expander.Header>
                                                <StackPanel Orientation="Horizontal">
                                                    <TextBlock Text="{Binding Path=Name}" />
                                                    <TextBlock Text=" - "/>
                                                    <TextBlock Text="{Binding Path=ItemCount}"/>
                                                </StackPanel>
                                            </Expander.Header>
                                            <ItemsPresenter />
                                        </Expander>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </GroupStyle.ContainerStyle>
                </GroupStyle>
            </DataGrid.GroupStyle>
        </DataGrid>
    </DockPanel>

</Window>
